package master;

/**
 * @author chenyw
 * @date 2022/9/3 19:39
 */
public class M201rangeBitwiseAnd {

    //找到这两个数的公共前缀，
    public int rangeBitwiseAnd(int left, int right) {
        int offset = 0;
        while (left != right) {
            left >>= 1;
            right >>= 1;
            offset++;
        }
        return left << offset;
    }


/*    //超时
    public int rangeBitwiseAnd(int left, int right) {
        int res = Integer.MAX_VALUE;
        for (int i = left; i <= right; i++) {
            res = res & i;
        }
        return res;
    }*/
}
